home *** CD-ROM | disk | FTP | other *** search
- <!--- This example uses find, findnocase, and findoneof
- to see if a substring exists in a web page --->
- <HTML>
- <HEAD>
- <TITLE>
- Find Example
- </TITLE>
- </HEAD>
-
- <BODY bgcolor=silver>
- <H3>Find Example</H3>
-
- <P>This example uses find, findnocase and findone of to see
- if a substring exists in a particular web page.
-
- <P>This example has been disabled for online viewing. Please use your copy of ColdFusion to view this example.
- <!---
- <FORM ACTION="find.cfm" METHOD="POST">
- Try entering a URL for the tag to return:
- <BR><INPUT TYPE="Text" size=25 NAME="urladdress" VALUE="http://www.allaire.com">
- <P>And a substring to search for:
- <BR><INPUT TYPE="Text" size=25 NAME="myString" VALUE="Allaire">
- <P>Pick a search type:
- <SELECT NAME="type">
- <OPTION VALUE="find" SELECTED>Case-Sensitive
- <OPTION VALUE="findNoCase">Case-Insensitive
- <OPTION VALUE="findOneOf">Find first instance
- </SELECT>
- <INPUT TYPE="Submit" NAME="" VALUE="get page">
- </FORM>
-
- <!--- sets a default value for a url to retrieve --->
- <CFPARAM name="urladdress" default="http://localhost/cfdocs/index.htm">
- <!--- if we have passed a url address in the form, we
- want to display the passed address --->
- <CFIF IsDefined("form.urladdress") is True>
- <!--- do simple error check to avoid crashing the
- tag --->
- <CFIF Trim(Form.urladdress) is "" or Trim(Form.urladdress) is "http://">
- <!--- if error condition tripped, set alternative --->
- <CFSET urlAddress ="http://localhost/cfdocs/index.htm">
- <H4>because you entered no url or an empty string, the tag
- will return the following address: http://localhost/cfdocs/index.htm</H4>
- <CFELSE>
- <!--- otherwise use address passed from form --->
- <CFSET urlAddress = form.urladdress>
- </CFIF>
- <!--- now use the CFHTTP tag to get the file content
- represented by urladdress --->
- <CFHTTP URL="#urladdress#"
- METHOD="GET"
- RESOLVEURL=YES>
- </CFHTTP>
- <CFELSE>
- <!--- the first time through, retrieve a URL that we know
- exists --->
- <CFHTTP URL="http://localhost/cfdocs/index.htm"
- METHOD="GET"
- RESOLVEURL=YES>
- </CFHTTP>
- </CFIF>
- <!--- wait to have a string for searching defined --->
- <CFIF IsDefined("form.myString") and IsDefined("form.type")>
- <!--- Now, test to see if the term was found --->
- A <CFIF form.type is "find">case-sensitive
- <CFSET tag="find">
- <CFELSEIF form.type is "findNoCase">case-insensitive
- <CFSET tag="findNoCase">
- <CFELSEIF form.type is "findOneOf">find the first instance of any character
- <CFSET tag="findOneOf">
- </CFIF> test for your string "<CFOUTPUT>#form.MyString#</CFOUTPUT>"
- in the url: "<CFOUTPUT>#urlAddress#</CFOUTPUT>"
-
- <!--- depending upon the action desired, perform
- different function --->
- <CFSWITCH EXPRESSION="#tag#">
- <CFCASE value="find">
- <CFSET TheAction = Find(form.MyString, CFHTTP.FileContent, 1)>
- </CFCASE>
- <CFCASE value="findNoCase">
- <CFSET TheAction = FindNoCase(form.MyString, CFHTTP.FileContent, 1)>
- </CFCASE>
- <CFCASE value="findOneof">
- <CFSET TheAction = FindOneOf(form.MyString, CFHTTP.FileContent, 1)>
- </CFCASE>
- <CFDEFAULTCASE>
- <CFSET TheAction = Find(form.MyString, CFHTTP.FileContent, 1)>
- </CFDEFAULTCASE>
- </CFSWITCH>
- <CFIF TheAction is not 0>
- <P>We found an instance of your string at index <CFOUTPUT>#theAction#</CFOUTPUT>
- <CFELSE>
- <P>No instance of your string was found.
- </CFIF>
- </CFIF>
- --->
- </BODY>
- </HTML>
-